package com.qms.repast.ui.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import com.qms.repast.commons.Constants;
import com.qms.repast.entity.reqbean.ShopId;
import com.qms.repast.entity.resbean.ShopDetailInfo;
import com.qms.repast.module.UserModule;
import com.qms.repast.ui.base.BasePresenter;
import com.qms.repast.ui.view.IDiningView;

import io.reactivex.observers.DisposableObserver;

/**
 * @author 泅渡者
 * @date 2018/9/17 0017
 * @describe:
 */
public class DiningPresenter extends BasePresenter<IDiningView> {

	private UserModule userModule;

	public DiningPresenter (Activity mContext, IDiningView mView) {
		super(mContext, mView);
		this.userModule = new UserModule(mContext);
	}

	/**
	 * 获取店铺详情
	 *
	 * @param shopId
	 */
	public void getShopInfo (ShopId shopId) {
		userModule.reqShopInfo(shopId, new DisposableObserver<ShopDetailInfo>() {
			@Override
			public void onError (Throwable throwable) {
				Logger.e(throwable.getMessage());
			}

			@Override
			public void onComplete () {
				Logger.d("Request is End");
			}

			@Override
			public void onNext (ShopDetailInfo shopDetailInfo) {
				Logger.json(new Gson().toJson(shopDetailInfo));
				if (null != shopDetailInfo && shopDetailInfo.getCode() == Constants.SUCCESS) {
					mView.showUI(shopDetailInfo);
				}
			}
		});
	}


}
